<template>
  <div class="wrap">
    <div class="header" v-if="inl!=0">
      <div class="left">
        <img :src="info.avatar" :onerror="defaultImg" class="headerUrl" alt />
        <div class="center">
          <div>
            <p>{{info.username}}</p>
            <span>订单数：{{info.total}}</span>
          </div>
          <p>{{info.signature}}</p>
        </div>
      </div>
      <div class="func">
       <p>商家</p>
      </div>
    </div>
    <div class="centers" v-if="orderList.length" :style="inl==0?'top:0':'top:2.586667rem'">
      <div class="item" v-for="item in orderList" :key="item.order_id">
        <div class="item-left">
          <img :src="item.order_image" @click="showMax(item.order_image)" :onerror="defaultImg2" class="avi" alt />
          <div class="productInfo">
            <p>规格：{{item.order_size}}</p>
            <p>价格：￥{{item.supplier_price	}}</p>
            <p>订单日期：{{item.create_time}}</p>
            <p v-if="inl==0">商家名称：{{item.supplier_name}}</p>
            <!-- <p>
              商家备注：
              <span style="color:#FF536B;">明天</span>
            </p>-->
          </div>
        </div>
        <div class="item-right">
          <!-- <div class="state">
           <p>{{item.send_state==1?'已到货':'未到货'}}</p> 
          </div> -->
          <div class="imgBo">
            <img
              class="start"
              :src="item.startSrc"
              alt
              @click="setState(item.order_id)"
              srcset
            />
            <img
              :src=" item.select ?require('../assets/select.png'):require('../assets/radio.png')"
              class="radio"
              alt
              @click="select(item)"
            />
          </div>
        </div>
      </div>
    </div>
    <div class="footer">
      <div>
        <p class="btn" @click="next">批量标记</p>
        <p class="orderNum">
          已选择个
          <span style="color:#3FD9C9;">{{num}}</span>
          订单
        </p>
      </div>
      <div @click="allSelect">
        <p>全选</p>
        <img
          :src="num===orderList.length?require('../assets/select.png'):require('../assets/radio.png')"
          class="all"
          alt
        />
      </div>
    </div>
    <van-action-sheet v-model="show" :round="false" title="标题">
      <div class="content">
        <div class="clo" @click="actionSelect(0)">
          <p>标记为</p>
          <img src="../assets/startWrite.png" alt />
        </div>
        <div class="clo" @click="actionSelect(1)">
          <p>标记为</p>
          <img src="../assets/startRed.png" alt />
        </div>
         <div class="clo" @click="actionSelect(2)">
          <p>标记为</p>
          <img src="../assets/startBlue.png" alt />
        </div>
        <div class="clo" @click="actionSelect(3)">
          <p>标记为</p>
          <img src="../assets/startGreen.png" alt />
        </div>
      </div>
    </van-action-sheet>
     <van-popup v-model="maxImgShow">
      <img :src="maxImg" class="maxImg" :onerror="defaultImg2" alt />
    </van-popup>
  </div>
</template>
<style lang="scss" scoped>
.maxImg{
  width: 100%;
}
.wrap {
  background: #f7f7f7;
  width: 100%;
  height: 100vh;
}
.header {
  height: 2.186667rem;
  padding: 0 0.4rem 0.4rem;
  background: #fff;
  display: flex;
  align-items: center;
  justify-content: space-between;

  .left {
    display: flex;
    align-items: center;
  }
  .headerUrl {
    width: 1.466667rem;
    height: 1.466667rem;
    border-radius: 50%;
    display: block;
    margin-top: 0.373333rem;
  }
  .center {
    margin-left: 0.4rem;
    div {
      // display: flex;
      // align-items: flex-end;
      margin-top: 15px;
      p {
        color: #555;
        font-size: 0.48rem;
      }
      span {
        color: #999;
        font-size: 0.293333rem;
        display: block;
        text-align: left;
        margin: 5px 0;
      }
    }
    p {
      color: #555;
      font-size: 0.266667rem;
      text-align: left;
    }
  }
 .func {
    margin-top: 15px;
    p:nth-of-type(1) {
      width: 2.24rem;
      height: 0.6rem;
      color: #999;
      border-radius: 0.4rem;
      font-size: 0.4rem;
      text-align: center;
      line-height: 0.6rem;
      margin-bottom: 0.266667rem;
    }
    p:nth-of-type(2) {
      width: 2.24rem;
      height: 0.6rem;
      background: rgba(63, 217, 201, 1);
      color: #fff;
      border-radius: 0.4rem;
      font-size: 0.373333rem;
      text-align: center;
      line-height: 0.6rem;
    }
  }
}
.centers {
  position: absolute;

  bottom: 1.2rem;
  left: 0;
  right: 0;
  overflow-y: scroll;
  .item {
    width: 9.466667rem;
    height: 2.333333rem;
    border-radius: 0.266667rem;
    background: #fff;
    margin: 0.186667rem auto 0;
    overflow: hidden;
    display: flex;
    justify-content: space-between;
    .item-left {
      display: flex;
      align-items: center;
    }
    .avi {
      width: 2rem;
      height: 2rem;
      object-fit: cover;
      border-radius: 0.266667rem;
      margin: 0 0.306667rem 0 0.133333rem;
      display: block;
      object-fit: cover;
    }
    .productInfo {
      display: flex;
      justify-content: space-between;
      flex-direction: column;
      height: 1.8rem;
      p {
        color: #555;
        font-size: 0.32rem;
        text-align: left;
      }
    }
    .item-right {
      display: flex;
      align-items: center;
      .imgBo {
        display: flex;
        align-items: center;
        justify-content: space-between;
        height: 1.8rem;
        width: 1.5rem;
        margin-right: .2rem;
        .start {
          width: 0.466667rem;
          height: 0.466667rem;
          display: block;
        }
        .radio {
          width: 0.453333rem;
          height: 0.453333rem;
          border-radius: 50%;
          display: block;
        }
      }
      .state {
        width: 2.4rem;
        display: flex;
        flex-direction: column;
        justify-content: space-between;
        p:nth-of-type(1) {
          color: #ff536b;
          font-size: 0.426667rem;
          text-align: left;
          margin-top: 0.266667rem;
          margin-bottom: 0.56rem;
        }
        p:nth-of-type(2) {
          width: 2.213333rem;
          height: 0.573333rem;
          border-radius: 0.266667rem;
          text-align: center;
          background: #3fd9c9;
          font-size: 0.373333rem;
          line-height: 0.573333rem;
          color: #fff;
        }
      }
    }
  }
}
.footer {
  background: #fff;
  position: fixed;
  bottom: 0;
  height: 1.2rem;
  width: 100%;
  left: 0;
  display: flex;
  align-items: center;
  justify-content: space-between;
  div {
    display: flex;
    align-items: center;
  }
  .btn {
    background: #3fd9c9;
    color: #fff;
    width: 2.72rem;
    height: 0.8rem;
    border-radius: 0.373333rem;
    font-size: 0.493333rem;
    margin-left: 0.733333rem;
    margin-right: 0.266667rem;
    line-height: 0.8rem;
  }
  .all {
    width: 0.453333rem;
    height: 0.453333rem;
    border-radius: 50%;
    display: block;
    margin-right: 0.533333rem;
    margin-left: 0.533333rem;
  }
}
.content {
  .clo {
    display: flex;
    align-items: center;
    justify-content: space-around;
    height: 1.2rem;
    img {
      width: 0.6rem;
      height: 0.6rem;
      display: block;
    }
  }
}
</style>
<script>
import { supplier, remark,followDele } from "@/utils/interface";
import { Toast, Dialog } from "vant";

export default {
  data() {
    return {
      orderList: [],
      num: 0,
      allSelectState: false,
      inof: {},
      inl: 1,
      show: false,
      orderItem: "",
      orderData: [],
      defaultImg:'this.src="'+ require('../assets/user2.png') +'"',
      defaultImg2: 'this.src="'+ require('../assets/timg.jpg') +'"',
      maxImgShow:false,
      maxImg:""
    };
  },
  created() {
    document.title = "送货订单";
    this.getList(this.$route.query.shopId);
    this.info = JSON.parse(this.$route.query.info);
    this.inl = this.$route.query.id;
  },
  methods: {
    next() {
      this.orderData = [];
      this.orderList.map(item => {
        if (item.select) {
          this.orderData.push( item.order_id);
        }
      });
      if (this.orderData.length == 0) {
        Dialog.alert({
          title: "提示",
          message: "请选择需要标记的订单"
        });
        return false;
      }
      this.show = true;
    },
    actionSelect(e) {
      this.show = false;
      let str = ""
      if(this.orderItem){
          str = this.orderItem
      }else if(this.orderData.length>0){
          str = this.orderData.toString()
      }
      remark({ star: e, orderList: str }).then(res => {
          this.orderItem = ""
          this.orderData = []
        if (res.data.code == 200) {
          Toast.success("修改标记成功");
           this.getList(this.$route.query.shopId);

        }
      });
    },
    setState(e) {
      console.log(e);
      this.orderItem = e;
      this.show = true;
    },
    getList(parentId) {
      supplier({ parentId }).then(res => {
        res.data.data.map(item => {
          item.select = false;
          item.create_time = item.create_time.split(' ')[0]
          switch(item.star){
            case 0:
            item.startSrc = require("../assets/startWrite.png")
            break;
            case 1:
            item.startSrc = require("../assets/startRed.png")
            break;
            case 2:
            item.startSrc = require( "../assets/startBlue.png")
            break;
            case 3:
            item.startSrc = require( "../assets/startGreen.png")
            break;

          }
        });
        this.orderList = res.data.data;
      });
    },
    select(item) {
      item.select = !item.select;
      this.num = 0;
      this.orderList.map(item => {
        if (item.select) {
          this.num++;
        }
      });
    },
    allSelect() {
      this.allSelectState = !this.allSelectState;
      if (this.allSelectState) {
        this.orderList.map(item => {
          item.select = true;
        });
        this.num = this.orderList.length;
      } else {
        this.orderList.map(item => {
          item.select = false;
        });
        this.num = 0;
      }
    },
    // 取消关注
    followdele() {
      Dialog.confirm({
        title: "提示",
        message: "是否取消关注该商家"
      })
        .then(() => {
          followDele({ bizUserId: this.info.user_id }).then(res => {
            if (res.data.code == 200) {
              Toast.success("取消成功");
              this.$router.go(-1);
            }
          });
        })
        .catch(() => {
          // on cancel
        });
    },
    showMax(s){
      this.maxImgShow = true
      this.maxImg = s
    }
  }
};
</script>